<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <!-- try  里面书写同步代码  catch 才能捕获到错误 -->
    <!-- try 里面如果是异步  catch捕获不到 -->
    <script>

// 模拟 try 里面 分别是同步和异步   观察catch  捕获错误的结果

        try {
            //  实例一
            // console.log(a);
            // let a = 1
            //-------------------------
            // 实例二
            setTimeout(() => {
                console.log(a);
                let a = 1
            })
        } catch (e) {
            console.log(e, '捕获异常');
        }
    </script>
</body>

</html>